package com.vviton.zyhj.consumer.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vviton.zyhj.common.base.AppConfig;
import com.vviton.zyhj.common.base.BaseService;
import com.vviton.zyhj.common.common.CodeConstants;
import com.vviton.zyhj.common.common.GlobalConstants;
import com.vviton.zyhj.common.common.ValidatorConstants;
import com.vviton.zyhj.common.dao.TYyxtDdglDhjlbMapper;
import com.vviton.zyhj.common.dao.TYyxtDdglYhdzbMapper;
import com.vviton.zyhj.common.dao.TYyxtJyglDhwlxxMapper;
import com.vviton.zyhj.common.dao.TYyxtLpglLpxxMapper;
import com.vviton.zyhj.common.dao.TYyxtLpglLpyfjdygxMapper;
import com.vviton.zyhj.common.dao.TYyxtPtglCyfxxMapper;
import com.vviton.zyhj.common.entity.TYyxtCode;
import com.vviton.zyhj.common.entity.TYyxtDdglDhjlb;
import com.vviton.zyhj.common.entity.TYyxtDdglYhdzb;
import com.vviton.zyhj.common.entity.TYyxtJyglDhwlxx;
import com.vviton.zyhj.common.entity.TYyxtLpglLpxx;
import com.vviton.zyhj.common.entity.TYyxtLpglLpyfjdygx;
import com.vviton.zyhj.common.utils.ErrorBean;
import com.vviton.zyhj.common.utils.ExpressQueryUtils;
import com.vviton.zyhj.common.utils.ResultJson;
import com.vviton.zyhj.common.utils.page.Page;
import com.vviton.zyhj.common.view.ParamJfjy;
import com.vviton.zyhj.common.view.ParamLjdh;
import com.vviton.zyhj.common.view.ParamLpdhcx;
import com.vviton.zyhj.common.view.ParamWddh;
import com.vviton.zyhj.common.view.ViewDhjlb;
import com.vviton.zyhj.common.view.ViewDhwlxx;
import com.vviton.zyhj.common.view.ViewKdxx;
import com.vviton.zyhj.common.view.ViewLpdhcx;
import com.vviton.zyhj.common.view.ViewLpxq;
import com.vviton.zyhj.common.view.ViewWlgzxx;
import com.vviton.zyhj.consumer.service.LpdhService;
import com.vviton.zyhj.content.CommonConstants;
import com.vviton.zyhj.cors.JfglCors;

/**
 * ClassName:LpdhServiceImpl <br/> 
 * Function: 礼品兑换ServiceImpl. <br/> 
 * Date:     2016年11月14日 上午11:46:47 <br/> 
 * 
 * @author   nifang
 * @version  1.0
 * @since    JDK 1.7
 */
public class LpdhServiceImpl extends BaseService implements LpdhService {
    
    /** 日志 */
    private static Logger logger = Logger.getLogger(LpdhServiceImpl.class);

    /** 礼品信息Mapper */
    @Autowired
    private TYyxtLpglLpxxMapper tYyxtLpglLpxxMapper;
    
    /** 礼品与附件对应关系Mapper */
    @Autowired
    private TYyxtLpglLpyfjdygxMapper tYyxtLpglLpyfjdygxMapper;
    
    /** 兑换记录Mapper **/
    @Autowired
    private TYyxtDdglDhjlbMapper tYyxtDdglDhjlbMapper;
    
    /** 用户地址Mapper **/
    @Autowired
    private TYyxtDdglYhdzbMapper tYyxtDdglYhdzbMapper;
    
    /** 兑换物流信息Mapper **/
    @Autowired
    private TYyxtJyglDhwlxxMapper tYyxtJyglDhwlxxMapper;
    
    /** 承运方信息Mapper **/
    @Autowired
    private TYyxtPtglCyfxxMapper tYyxtPtglCyfxxMapper;
    
    /** 配置文件 **/
    @Autowired
    private AppConfig appConfig;
    
    /** 积分管理Cors **/
    @Autowired
    private JfglCors jfglCors;
    
    /**
     * 
     * getLpdhPagination,(礼品兑换分页查询). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月14日 <br/>
     * =============================================================== <br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月14日 <br/>
     * Modify Description: <br/>
     * =============================================================== <br/>
     * @param param 分页参数
     * @return 礼品兑换分页信息
     * @since JDK 1.7
     */
    @Override
    public Page getLpdhPagination(ParamLpdhcx param) {
        
        logger.info("礼品兑换分页查询begin");
        param.setZkzt(CodeConstants.ZKZT_SJ);
        param.setFjfl(CodeConstants.FJFL_LPLOGO);
        
        if (param.getZh() != null) {
            Integer syjf = jfglCors.getYhsyjf(CodeConstants.JFYHLX_YH, param.getZh());
            param.setYyjf(syjf);
        }
        
        Page page = new Page();
        page.setCurrPage(param.getCurrPage());
        page.setPageSize(param.getPageSize());
        page.setParam(param);
        
        int count = tYyxtLpglLpxxMapper.countLpxxPagination(page);
        page.setTotal(count);
        
        List<ViewLpdhcx> lpxxList = new ArrayList<ViewLpdhcx>();
        if (count > 0) {
            lpxxList = tYyxtLpglLpxxMapper.getLpxxPagination(page);
            page.setData(lpxxList);
        }
        logger.info("礼品兑换分页查询end");
        return page;
    }

    /**
     * 
     * getLpxq,(获取礼品详情). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月14日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月14日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param lpid 礼品编号
     * @param zh 账号
     * @param ywy 业务域
     * @return 礼品详情
     * @since JDK 1.7
     */
    @Override
    public ViewLpxq getLpxq(String lpid, String zh, String ywy) {
        
        logger.info("获取礼品详情begin");
        
        TYyxtLpglLpxx lpxx = tYyxtLpglLpxxMapper.getLpxxByIdAndYwy(lpid, ywy);
        if (lpxx == null) {
            logger.info("根据礼品编号找不到礼品信息");
            return null;
        }
        
        ViewLpxq viewLpxq = new ViewLpxq();
        CommonConstants.copyProperties(viewLpxq, lpxx);
        
        // 获取礼品与附件对应关系
        List<TYyxtLpglLpyfjdygx> lpyfjdygxList = tYyxtLpglLpyfjdygxMapper.getLpyfjdygxBylpid(lpid, ywy);
        List<TYyxtLpglLpyfjdygx> lpsltList = new ArrayList<TYyxtLpglLpyfjdygx>();
        for (TYyxtLpglLpyfjdygx lpyfjdygx : lpyfjdygxList) {
            if (lpyfjdygx.getFjfl().equals(CodeConstants.FJFL_LPLOGO)) { // 礼品logo
                viewLpxq.setLplogo(lpyfjdygx.getFjdz());
            } else if (lpyfjdygx.getFjfl().equals(CodeConstants.FJFL_LPXQ)) { // 礼品详情
                ResultJson res = this.readTxtFromDFS(appConfig.getDfsHost() + "/" + lpyfjdygx.getFjdz());
                if (res.isResult()) {
                    viewLpxq.setLpjs(res.getObject().toString());
                }
            } else if (lpyfjdygx.getFjfl().equals(CodeConstants.FJFL_SLT)) { // 礼品缩略图
                lpsltList.add(lpyfjdygx);
            }
        }
        
        if (lpsltList.size() > 0) {
            viewLpxq.setLpsltList(lpsltList);
        }
        
        
        if (zh != null) {
            Integer syjf = jfglCors.getYhsyjf(CodeConstants.JFYHLX_YH, zh);
            viewLpxq.setYyjf(syjf);
        }
        
        logger.info("获取礼品详情end");
        return viewLpxq;
    }

    /**
     * 
     * getWddhPagination,(分页查询我的兑换信息). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月15日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月15日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param param 查询参数
     * @return 我的兑换信息
     * @since JDK 1.7
     */
    @Override
    public Page getWddhPagination(ParamWddh param) {
        
        logger.info("分页查询我的兑换列表begin");
        
        Page page = new Page();
        page.setCurrPage(param.getCurrPage());
        page.setPageSize(param.getPageSize());
        page.setParam(param);
        
        int count = tYyxtDdglDhjlbMapper.countWddhPagination(page);
        page.setTotal(count);
        
        List<ViewDhjlb> viewDhjlbList = new ArrayList<ViewDhjlb>();
        Map<String, TYyxtCode> sfxnMap = this.getCodeMapCodeclass(CodeConstants.YESORNO);
        Map<String, TYyxtCode> dhztMap = this.getCodeMapCodeclass(CodeConstants.DHZT);
        if (count > 0) {
            viewDhjlbList = tYyxtDdglDhjlbMapper.getWddhPagination(page);
            for (ViewDhjlb viewDhjlb : viewDhjlbList) {
                // 是否虚拟描述
                String sfxnmc = sfxnMap.get(CodeConstants.YESORNO + viewDhjlb.getSfxn()).getCodedesc();
                // 兑换状态描述
                String dhztmc = dhztMap.get(CodeConstants.DHZT + viewDhjlb.getZt()).getCodedesc();
                
                viewDhjlb.setSfxnDesc(sfxnmc);
                viewDhjlb.setDhztDesc(dhztmc);
            }
            
            page.setData(viewDhjlbList);;
        }
        
        logger.info("分页查询我的兑换列表end");
        return page;
        
    }

    /**
     * 
     * updateShdz,(编辑收货地址). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月16日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月16日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param param 用户地址entity
     * @return 执行结果
     * @since JDK 1.7
     */
    @Override
    public ResultJson updateShdz(TYyxtDdglYhdzb param) {
        
        logger.info("新增/修改收货地址begin");
        
        ResultJson resultJson = new ResultJson(false);
        List<ErrorBean> errCodeList = new ArrayList<ErrorBean>();
        
        // 账号不能为空
        if (StringUtils.isBlank(param.getZh())) {
            resultJson.setMessage(ValidatorConstants.E1200);
            return resultJson;
        }
        
        // 业务域不能为空
        if (StringUtils.isBlank(param.getYwy())) {
            resultJson.setMessage(ValidatorConstants.E1204);
            return resultJson;
        }
        
        // 收货详细地址不能为空
        if (StringUtils.isBlank(param.getShxxdz())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1201);
            errCodeList.add(errorBean);
        }
        
        // 收货人不能为空
        if (StringUtils.isBlank(param.getShr())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1202);
            errCodeList.add(errorBean);
        }
        
        // 收货人手机号码不能为空
        if (StringUtils.isBlank(param.getShrsjhm())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1203);
            errCodeList.add(errorBean);
        }
        
        if (errCodeList.size() > 0) {
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        Date now = new Date();
        if (param.getId() == null) { // 新增收货地址
            param.setId(this.getKey());
            param.setDelflag(GlobalConstants.DELFLAG_ADD);
            param.setVersions(this.getVersion());
            param.setOperatercode(param.getZh());
            param.setOperatetime(now);
            param.setCreatercode(param.getZh());
            param.setCreatertime(now);
            tYyxtDdglYhdzbMapper.insertYhdzb(param);
        } else { // 修改收货地址
            param.setDelflag(GlobalConstants.DELFLAG_UPDATE);
            param.setVersions(this.getVersion());
            param.setOperatercode(param.getZh());
            param.setOperatetime(now);
            tYyxtDdglYhdzbMapper.updateYhdzbById(param);
        }
        
        logger.info("新增/修改收货地址end");
        resultJson.setResult(true);
        return resultJson;
    }

    /**
     * 
     * getShdz,(获取收货地址). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月17日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月17日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param zh 账号
     * @return 收货地址
     * @since JDK 1.7
     */
    @Override
    public TYyxtDdglYhdzb getShdz(String zh) {
        
        TYyxtDdglYhdzb yhdz = tYyxtDdglYhdzbMapper.getYhdzByZh(zh);
        return yhdz;
    }

    /**
     * 
     * updateLjdh,(立即兑换). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年11月17日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年11月17日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param paramLjdh 立即兑换传入参数
     * @return 执行结果
     * @since JDK 1.7
     */
    @Override
    public ResultJson updateLjdh(ParamLjdh paramLjdh) {
        
        logger.info("立即兑换begin, 兑换人：" + paramLjdh.getDhrzh() + ", 礼品编号：" + paramLjdh.getLpid());
        
        ResultJson resultJson = new ResultJson(false);
        List<ErrorBean> errCodeList = new ArrayList<ErrorBean>();
        
        // 礼品编号不能为空
        if (StringUtils.isBlank(paramLjdh.getLpid())) {
            resultJson.setMessage(ValidatorConstants.E1205);
            return resultJson;
        }
        
        // 兑换人账号不能为空
        if (StringUtils.isBlank(paramLjdh.getDhrzh())) {
            resultJson.setMessage(ValidatorConstants.E1200);
            return resultJson;
        }
        
        // 兑换类别不能为空
        if (StringUtils.isBlank(paramLjdh.getDhlb())) {
            resultJson.setMessage(ValidatorConstants.E1207);
            return resultJson;
        }
        
        // 业务域不能为空
        if (StringUtils.isBlank(paramLjdh.getYwy())) {
            resultJson.setMessage(ValidatorConstants.E1204);
            return resultJson;
        }
        
        // 收货详细地址不能为空
        if (StringUtils.isBlank(paramLjdh.getShxxdz())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1208);
            errCodeList.add(errorBean);
        }
        
        // 收货人不能为空
        if (StringUtils.isBlank(paramLjdh.getShr())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1209);
            errCodeList.add(errorBean);
        }
        
        // 收货人电话号码不能为空
        if (StringUtils.isBlank(paramLjdh.getShrdhhm())) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1210);
            errCodeList.add(errorBean);
        }
        
        if (errCodeList.size() > 0) {
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        TYyxtLpglLpxx lpxx = tYyxtLpglLpxxMapper.getLpxxByIdAndYwy(paramLjdh.getLpid(), paramLjdh.getYwy());
        if (lpxx == null) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1211);
            errCodeList.add(errorBean);
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        // 判断产品在库状态
        if (!lpxx.getZkzt().equals(CodeConstants.ZKZT_SJ)) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1212);
            errCodeList.add(errorBean);
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        // 判断是否有库存
        if (lpxx.getLpsl() <= lpxx.getDhsl()) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1213);
            errCodeList.add(errorBean);
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        // 判断兑换人剩余积分是否足够
        Integer syjf = jfglCors.getYhsyjf(CodeConstants.JFYHLX_YH, paramLjdh.getDhrzh());
        if (syjf < lpxx.getJf()) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.setErrorData(ValidatorConstants.E1214);
            errCodeList.add(errorBean);
            resultJson.setErrorList(errCodeList);
            return resultJson;
        }
        
        Date now = new Date();
        // 新增兑换记录表
        TYyxtDdglDhjlb dhjl = new TYyxtDdglDhjlb();
        String dhjlid = this.getKey();
        dhjl.setId(dhjlid);
        dhjl.setLpid(lpxx.getId());
        dhjl.setLpmc(lpxx.getLpmc());
        dhjl.setDhlb(paramLjdh.getDhlb());
        dhjl.setJf(lpxx.getJf());
        dhjl.setSfxn(lpxx.getSfxn());
        dhjl.setDhrzh(paramLjdh.getDhrzh());
        dhjl.setDhsj(now);
        dhjl.setDhrmc(paramLjdh.getDhrmc());
        dhjl.setTgflx(lpxx.getTgflx());
        if (lpxx.getTgflx().equals(CodeConstants.TGFLX_YH)) {
            dhjl.setSfshzf(CodeConstants.YESORNO_NO);
        } else if (lpxx.getTgflx().equals(CodeConstants.TGFLX_HZF)) {
            dhjl.setSfshzf(CodeConstants.YESORNO_YES);
        }
        dhjl.setHzfid(lpxx.getHzfid());
        dhjl.setTgfzh(lpxx.getTgfzh());
        dhjl.setTgfmc(lpxx.getTgfmc());
        dhjl.setZt(CodeConstants.DHZT_WFF);
        dhjl.setYwy(paramLjdh.getYwy());
        dhjl.setDelflag(GlobalConstants.DELFLAG_ADD);
        dhjl.setVersions(this.getVersion());
        dhjl.setOperatercode(paramLjdh.getDhrzh());
        dhjl.setOperatetime(now);
        dhjl.setCreatercode(paramLjdh.getDhrzh());
        dhjl.setCreatertime(now);
        tYyxtDdglDhjlbMapper.insertDhjlb(dhjl);
        
        // 新增兑换物流信息表
        TYyxtJyglDhwlxx dhwlxx = new TYyxtJyglDhwlxx();
        dhwlxx.setId(this.getKey());
        dhwlxx.setZh(paramLjdh.getDhrzh());
        dhwlxx.setDhid(dhjlid);
        dhwlxx.setShxxdz(paramLjdh.getShxxdz());
        dhwlxx.setShr(paramLjdh.getShr());
        dhwlxx.setShrdhhm(paramLjdh.getShrdhhm());
        dhwlxx.setYwy(paramLjdh.getYwy());
        dhwlxx.setDelflag(GlobalConstants.DELFLAG_ADD);
        dhwlxx.setVersions(this.getVersion());
        dhwlxx.setOperatercode(paramLjdh.getDhrzh());
        dhwlxx.setOperatetime(now);
        dhwlxx.setCreatercode(paramLjdh.getDhrzh());
        dhwlxx.setCreatertime(now);
        tYyxtJyglDhwlxxMapper.insertDhwlxx(dhwlxx);
        
        // 更新礼品信息表
        lpxx.setDhsl(lpxx.getDhsl() + 1);
        lpxx.setDelflag(GlobalConstants.DELFLAG_UPDATE);
        lpxx.setVersions(this.getVersion());
        lpxx.setOperatercode(paramLjdh.getDhrzh());
        lpxx.setOperatetime(now);
        tYyxtLpglLpxxMapper.updateLpxxDhsl(lpxx);
        
        // 跨积分库更新积分交易信息
        String xw = CommonConstants.XW_JFDH;
        String hqzhlx = null;
        if (lpxx.getTgflx().equals(CodeConstants.TGFLX_YH)) {
            hqzhlx = CommonConstants.JFZHLX_XFZ;
        } else {
            hqzhlx = CommonConstants.JFZHLX_HZF;
        }
        
        ParamJfjy paramJfjy = new ParamJfjy();
        paramJfjy.setHqzhlx(hqzhlx);
        paramJfjy.setHqzh(lpxx.getTgfzh());
        paramJfjy.setHqmc(lpxx.getTgfmc());
        paramJfjy.setHqxw(xw);
        paramJfjy.setJyfz(lpxx.getJf());
        paramJfjy.setZcywId(dhjlid);
        paramJfjy.setZczhlx(CommonConstants.JFZHLX_XFZ);
        paramJfjy.setZczh(paramLjdh.getDhrzh());
        paramJfjy.setZcmc(paramLjdh.getDhrmc());
        paramJfjy.setZcxw(xw);
        paramJfjy.setBz(dhjlid);
        paramJfjy.setNc(paramLjdh.getDhrmc());
        paramJfjy.setHzfmc(lpxx.getTgfmc());
//        paramJfjy.setZcjfhdid(hdbh);  // 支出积分活动编号
        jfglCors.insertJfjy(paramJfjy);
        
        resultJson.setResult(true);
        logger.info("立即兑换end, 兑换人：" + paramLjdh.getDhrzh() + ", 礼品编号：" + paramLjdh.getLpid());
        return resultJson;
    }

    /**
     * 
     * getDhwlxx,(查询兑换物流信息). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年12月22日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年12月22日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param dhid 兑换编号
     * @return 兑换物流信息
     * @since JDK 1.7
     */
    @Override
    public ViewDhwlxx getDhwlxx(String dhid) {
        
        logger.info("查询兑换物流信息begin--兑换编号：" + dhid);
        
        ViewDhwlxx dhwlxx = tYyxtJyglDhwlxxMapper.getViewDhwlxxByDhid(dhid);
        
        logger.info("查询兑换物流信息end--兑换编号：" + dhid);
        return dhwlxx;
    }

    /**
     * 
     * getWlgzxx,(查询物流跟踪信息). <br/>
     * Author: nifang <br/>
     * Create Date: 2016年12月22日 <br/>
     * ===============================================================<br/>
     * Modifier: nifang <br/>
     * Modify Date: 2016年12月22日 <br/>
     * Modify Description:  <br/>
     * ===============================================================<br/>
     * @param dhid 兑换编号
     * @return 物流跟踪信息
     * @since JDK 1.7
     */
    @Override
    public ViewWlgzxx getWlgzxx(String dhid) {
        
        TYyxtJyglDhwlxx dhwlxx = tYyxtJyglDhwlxxMapper.getDhwlxxByDhid(dhid);
        ViewWlgzxx wlgz = new ViewWlgzxx();
        if (dhwlxx != null && StringUtils.isNotBlank(dhwlxx.getCyfbm()) && StringUtils.isNotBlank(dhwlxx.getHydh())) {
            //调用物流信息的接口
            try {
                JSONObject wlgzxx = ExpressQueryUtils.getExpressInfo(dhwlxx.getCyfbm(), dhwlxx.getHydh());

                String flag = wlgzxx.getString("flag");
                wlgz.setExpSpellName(wlgzxx.getString("expSpellName"));
                wlgz.setExpTextName(wlgzxx.getString("expTextName"));
                wlgz.setMailNo(wlgzxx.getString("mailNo"));
                wlgz.setTel(wlgzxx.getString("tel"));
                wlgz.setUpdate(wlgzxx.getString("update"));
                wlgz.setStatus(wlgzxx.getString("status"));
                wlgz.setUpdateStr(wlgzxx.getString("updateStr"));
                wlgz.setRet_code(wlgzxx.getString("ret_code"));
                if ("true".equals(flag)) {
                    wlgz.setFlag(true);
                    List<ViewKdxx> viewKdxxList = new ArrayList<ViewKdxx>();
                    JSONArray wlgzxxArray = wlgzxx.getJSONArray("data");
                    if (wlgzxxArray != null) {
                        Iterator<Object> iterator = wlgzxxArray.iterator();
                        while (iterator.hasNext()) {
                            JSONObject expTemp = (JSONObject) iterator.next();
                            ViewKdxx kdxx = new ViewKdxx();
                            kdxx.setContext(expTemp.getString("context"));
                            kdxx.setTime(expTemp.getString("time"));
                            viewKdxxList.add(kdxx);
                        }
                        wlgz.setKdxxList(viewKdxxList);
                    }

                } else {
                    wlgz.setFlag(false);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            wlgz.setFlag(false);
        }
        return wlgz;
    }
    
}

